﻿using CN.T.Backend.Application.System.Services;
using CN.T.Backend.Application.System.Utility;
using DRNetCore.Api.Models;
using Furion.JsonSerialization;
using Furion.UnifyResult;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.ApiExplorer;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CN.T.Backend.Application.System
{
    /// <summary>
    /// 获取永久授权码接口
    /// </summary>
    public class TPlusAppService: IDynamicApiController
    {
        private readonly ITPlusService _serviceDal;
        public readonly ISystemService _systemService;
        public TPlusAppService(ISystemService service, ITPlusService tPlusService)
        {
            _systemService = service;
            _serviceDal = tPlusService;
        }
        /// <summary>
        /// 获取永久授权token
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        [ProducesResponseType( 200,Type=typeof(ApiResult))]//自定义接口返回
        public async Task<ApiResult> GetToken(string? code)
        {
            Tuple<bool, string, dynamic?> data =await _serviceDal.GetFristTokenAsync(code);


            return new(){ Msg = data.Item2,data = data.Item3};
        }
        /// <summary>
        /// 获取永久授权Token失效后执行
        /// </summary>
        /// <returns></returns>
        public async Task<string> GetPermanentTokenAsync()
        {
            var data=await _serviceDal.PermanentTokenAsync();
            return data.Item3;
        }
        /// <summary>
        /// 接口回调函数
        /// </summary>
        /// <param name="pulsMsg"></param>
        /// <returns></returns>
        public async Task<string> PostReceive(TPulsMsg pulsMsg)
        {
           var data= await _serviceDal.Receive(pulsMsg);
            //return "{\"result\":\"success\"}";
            return "success";
        }
        /// <summary>
        /// 获取企业临时授权码
        /// </summary>
        /// <returns></returns>
        public async Task<bool> GetQylssqm()
        {
            var data =await _serviceDal.Qylssqm();
            return true;
        }
    }

}
